#!/usr/bin/python

import os

vars = Variables()
vars.Add(BoolVariable('debug', 'Enable debug build', 0))
vars.Add(BoolVariable('profile', 'Enable profile build', 0))
vars.Add(BoolVariable('verbose', 'Show verbose compiling output', 0))
vars.Add(BoolVariable('clang', 'Use clang compiler', 0))

env = Environment(variables = vars)
env['ENV']['TERM'] = os.environ['TERM']
Help(vars.GenerateHelpText(env))
try:
	import multiprocessing
	env.SetOption('num_jobs', multiprocessing.cpu_count())
except NotImplementedError:
	pass

if env['clang']:
	env['CXX'] = 'clang++'
	env['CC'] = 'clang'
	env.Append(CXXFLAGS = '-stdlib=libc++', LINKFLAGS='-stdlib=libc++')
if env['debug']:
	env.Append(CCFLAGS = '-g -Wall')
else:
	env.Append(CCFLAGS = '-O2 -DNDEBUG')
if env['profile']:
	env.Append(CCFLAGS = '-pg', _LIBFLAGS = ' -pg')
if not env['verbose']:
	env['CCCOMSTR'] = env['CXXCOMSTR'] = "compiling: $TARGET"
	env['LINKCOMSTR'] = "linking: $TARGET"
	env['ARCOMSTR'] = "archiving: $TARGET"

env.Append(CPPPATH = ['include'])

source_files = env.Object(Glob('*.cpp') + \
                          Glob('leveleditor/*.cpp') + \
                          Glob('engine/*.cpp') + \
                          Glob('gui/*.cpp'), CPPFLAGS='-std=c++11')

env.ParseConfig("pkg-config jngl --cflags --libs")
env.Append(LIBS = Split('boost_filesystem boost_serialization boost_system pthread'))

env.Append(CCFLAGS = '-DENABLE_BINRELOC')

env.Program(target = "../jntetri",
            source = source_files + Glob('engine/linux/*.c'))
